﻿using System;
using ElectronicCommerce.Framework.Configuration.Entities;

namespace ElectronicCommerce.Framework.ExceptionManagement.Interface
{
    /// <summary>
    /// 异常处理类的基类
    /// </summary>
    public abstract class ExHandlerBase
    {
        // 存放异常日志记录对象的队列
        protected System.Collections.ArrayList lstLogHandler;

        // 异常配置信息
        protected Configuration.Entities.ExHandler m_ExHandlerConfig;

        public ExHandlerBase()
        {
            lstLogHandler = new System.Collections.ArrayList();
        }

        /// <summary>
        /// 根据配置文件加载所有的异常记录器对象实例
        /// </summary>
        /// <param name="config">The config.</param>
        public void LoadLogHandler(Configuration.Entities.ExHandler config)
        {
            m_ExHandlerConfig = config;

            // 遍历当前ExHandler节点的所有LogHandler子节点
            foreach (Configuration.Entities.LogHandler logConfig in config.LogHandlerList)
            {
                // 根据配置信息，反射加载异常日志记录对象，并存入队列
                object exLogHandler = System.Activator.CreateInstance(Type.GetType(logConfig.Type));
                lstLogHandler.Add(exLogHandler);
            }
        }

        /// <summary>
        /// Gets the ex hanlder config.
        /// </summary>
        /// <value>The ex hanlder config.</value>
        public Configuration.Entities.ExHandler ExHanlderConfig
        {
            get
            {
                return m_ExHandlerConfig;
            }
        }

        /// <summary>
        /// 处理异常信息
        /// </summary>
        /// <param name="ex">The ex.</param>
        /// <param name="strUserId">The STR user id.</param>
        /// <param name="strErrorCode">The STR error code.</param>
        /// <param name="strExtention">The STR extention.</param>
        /// <returns></returns>
        abstract public string ProcessExeception(Exception ex, string strUserId, string strErrorCode, string strErrorMessage, string pageAlias, out MessageBoxType messageType, params string[] strExtention);
    }
}
